<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BOSS.Framework.Search.Result.ISearchResult>" %>
<%@ Import Namespace="BOSS.Domain.Customers" %>
<%@ Import Namespace="BOSS.Web.Extensions" %>

<%
    var data = Model.UnderlayerItems.OfType<CustomerCard>().Select(x => new
    {
        Id = x.Id,
        CardNumber = x.CardNumber,
        Cardholder = new
        {
            Id = x.Cardholder == null ? 0 : x.Cardholder.Id,
            Name = x.Cardholder == null ? "" : x.Cardholder.Name,
            Mobile = x.Cardholder == null ? "" : x.Cardholder.Mobile
        },
        CustomerAccount = new
        {
            Id = x.CustomerAccount == null ? 0 : x.CustomerAccount.Id,
            AccountNumber = x.CustomerAccount == null ? "" : x.CustomerAccount.AccountNumber,
            Customer = new 
            {
                Id = x.CustomerAccount == null || x.CustomerAccount.Customer == null ? 0 : x.CustomerAccount.Customer.Id,
                Name = x.CustomerAccount == null || x.CustomerAccount.Customer == null ? "" : x.CustomerAccount.Customer.Name
            } 
        },
        State = x.State.GetDescription(),
        ActivationDate = Html.EncodeDateTime(x.ActivationDate),

    });
%>

<%= Html.ToJson(data) %>